<template>
  <div class="main">
    <div class="topTitle">库房</div>
    <div class="form_content">
      <NScrollbar>
        <div class="content">
          <NSpace>
            <NForm
              ref="formRef"
              :model="formValue"
              :rules="rules"
              label-placement="left"
              :label-width="130"
              label-align="right"
            >
              <NSpace>
                <NFormItem
                  label="层级类型:"
                  path="clueName"
                >
                  <NSelect
                    :options="listOption"
                    v-model:value="formValue.provideId"
                    placeholder="请选择位置"
                    clearable
                    style="width: 150px; margin-right: 10px"
                  />
                  <NSelect
                    :options="listOption"
                    v-model:value="formValue.provideId"
                    placeholder="请选择排数"
                    clearable
                    style="width: 150px; margin-right: 10px"
                  />
                  <NSelect
                    :options="listOption"
                    v-model:value="formValue.provideId"
                    placeholder="请选择面"
                    clearable
                    style="width: 150px; margin-right: 10px"
                  />
                  <NSelect
                    :options="listOption"
                    v-model:value="formValue.provideId"
                    placeholder="请选择节数"
                    clearable
                    style="width: 150px; margin-right: 10px"
                  />
                </NFormItem>
              </NSpace>
            </NForm>
          </NSpace>
        </div>
      </NScrollbar>
    </div>
  </div>
  <FixedAction>
    <NSpace justify="center">
      <NButton
        style="width: 78px"
        ghost
        @click="goBack"
      >
        取消
      </NButton>
      <NButton
        type="primary"
        style="width: 78px"
        @click="confirm"
        :disabled="loading"
        :loading="loading"
      >
        保存
      </NButton>
    </NSpace>
  </FixedAction>
</template>

<script setup lang="ts">
import { ref, onMounted, computed, reactive } from 'vue'
import {
  NSpace,
  NForm,
  NInput,
  NFormItem,
  NButton,
  NScrollbar,
  NSelect,
  useMessage,
  NRadioGroup,
  NRadio
} from 'naive-ui'
import type { FormInst } from 'naive-ui'
import router from '@/router'
import { useTagStore } from '@/stores/layout'
import FixedAction from '@/components/FixedAction.vue'
import { sendRequest } from '@/utils/api'
import VUpload from '@/views/OA/Common/Upload.vue'
import type { HttpResponse } from '@/utils/http'

const tags = useTagStore().tags
const message = useMessage()
const loading = ref(false)
const formRef = ref<FormInst | null>(null)
const listOption = ref([])
const listZOption = ref([])
const formValue = reactive({
  clueName: '',
  provideId: null,
  transferUserId: '',
  receiveUserId: '',
  RadioValue: null,
  fileIds: ''
})
const songs = ref([
  {
    value: 1,
    label: '启用'
  },
  {
    value: 2,
    label: '禁用'
  }
])
const fileList: any = ref([])
const rules = {
  clueName: {
    required: true,
    message: '请输入线索名称',
    trigger: 'blur'
  },
  transferUserId: {
    required: true,
    message: '请输入移交人',
    trigger: ['change', 'blur']
  },
  receiveUserId: {
    required: true,
    message: '请输入接收人',
    trigger: 'blur'
  }
}
// 附件
const handleUploadList = (v: any) => (formValue.fileIds = v)
// 返回
const goBack = () => {
  const index = tags.findIndex((item: any) => item.path === router.currentRoute.value.fullPath)
  
    tags.splice(index, 1)
if (tags.length == 0) {
    router.push({ path: '/OA/Workbench/UserDesktop' })
  } else history.back()
}
//征集信息下拉
const getFunction = async () => {
  listOption.value = []
  const [error, res] = await sendRequest<HttpResponse>({
    module: 'collectNotice',
    api: 'listByParentCode',
    override: {
      params: {
        dicCode: 'A40'
      }
    }
  })
  if (error) return message.error(error.message)
  res.data.forEach((i: any) => {
    // @ts-ignore
    listOption.value.push({ label: i.dicName, value: i.dicCode })
  })
}
//证件类型下拉
const getZFunction = async () => {
  listZOption.value = []
  const [error, res] = await sendRequest<HttpResponse>({
    module: 'collectNotice',
    api: 'listByParentCode',
    override: {
      params: {
        dicCode: 'A37'
      }
    }
  })
  if (error) return message.error(error.message)
  res.data.forEach((i: any) => {
    // @ts-ignore
    listZOption.value.push({ label: i.dicName, value: i.dicCode })
  })
}
//修改
const confirm = () => {
  formRef.value?.validate(async (err: any) => {
    if (err) return
    loading.value = true
    const [error, res] = await sendRequest<HttpResponse>({
      module: 'collectNotice',
      api: 'save',
      override: {
        data: {
          ...formValue
        }
      }
    })
    loading.value = false
    if (error) return message.error(error.message)
    message.success(res.msg)
    goBack()
  })
}
onMounted(() => {
  getFunction()
  getZFunction()
})
</script>

<style scoped lang="scss">
@mixin CommonFont {
  font-size: 16rem;
  font-family: PingFangSC, PingFang SC;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
}

.commonWidth {
  width: 360rem;
}

.main {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  overflow: hidden;

  .topTitle {
    width: 100%;
    height: 64rem;
    border-bottom: 1px solid #fff;
    padding: 20rem;
    margin-bottom: 20rem;
    @include CommonFont;
  }

  .form_content {
    width: 100%;
    height: 100%;
    padding: 20rem 20rem 0;

    .content {
      display: flex;
      align-items: center;
      flex-direction: column;
      width: 100%;
      height: 100%;
      padding: 18rem 33rem 120rem;
      overflow-y: scroll;
      background-color: #ebeceb;

      .scope {
        width: 360rem;
        height: 130rem;
        background: #e1e1e1;
        margin-bottom: 25rem;
      }
    }
  }
}

.content::-webkit-scrollbar {
  display: none;
}

:deep(.n-spin-container) {
  width: 100%;
  height: 100%;
}

:deep(.n-scrollbar-container) {
  width: 100%;
  height: 100%;
}

:deep(.n-scrollbar-content) {
  width: 100%;
  height: 100%;
}

:deep(.n-spin-content) {
  width: 100%;
  height: 100%;
}
</style>
